package com.kezhong.app.sample;

import android.Manifest;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

import com.bumptech.glide.Glide;

import com.example.empty.photo3.DpUtils;
import com.example.empty.photo3.PhotoGetBack;
import com.example.empty.photo3.TakePhotoDialog;
import com.tbruyelle.rxpermissions2.Permission;
import com.tbruyelle.rxpermissions2.RxPermissions;

import java.util.List;
import java.util.function.Consumer;


public class MainActivity extends AppCompatActivity implements PhotoGetBack {

    private static final String authority = "com.kezhong.app.component.photo.fileProvider";

    private Button mPhotoBtn;
    private Button mGalleryBtn;
    private ImageView mPhotoImg;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        DpUtils.init(this);
        mPhotoBtn = findViewById(R.id.btn_photo);
        mGalleryBtn = findViewById(R.id.btn_gallery);
        mPhotoImg = findViewById(R.id.img_photo);
        mPhotoBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                camera();
            }
        });
        mGalleryBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                selectPhoto();
            }
        });
    }

    private void selectPhoto() {
        TakePhotoDialog dialog = TakePhotoDialog.createDialog(this, true, true, "拍照", "从相册选择", this);
        dialog.show(getSupportFragmentManager(),dialog.getClass().getSimpleName());
    }

    private void camera(){
        TakePhotoDialog dialog = TakePhotoDialog.createDialog(this, true, true, "拍照", "从相册选择", this);
        dialog.show(getSupportFragmentManager(), dialog.getClass().getSimpleName());
    }

    private void toast(String msg) {
        Toast.makeText(MainActivity.this, msg, Toast.LENGTH_SHORT).show();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        Log.d("dwqdwqdwq","首页onActivityResult");
    }

    @Override
    public void getPhotos(List<String> photos) {
        Log.d("dwqdwqdwq","传入了");
        Glide.with(this).load(photos.get(0)).into(mPhotoImg);
    }

    @Override
    public void error() {
        Log.d("dwqdwqdwq","报错了");
    }
}
